const express = require('express')
const router = express.Router()


//导入数据库 sqlFn('sql',[],res=>{})
const sqlFn = require('../mysql')


router.get('/getParams', (req, res) => {
    const sql = "select * from params where category=?";
    let arr = [req.query.param]
    sqlFn(sql, arr, (result) => {
        res.send({
            res_code: 1,
            data:result
        });
        console.log('result:',result)
    })
});

router.post('/setParams', (req, res) => {
    const sql = "insert into params(category,param) values(?,?)";
    let arr = [req.query.category,req.query.params]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});

router.post('/addParams', (req, res) => {
    const sql = "update params set param=? where category=?";
    let arr = [req.query.params,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});


router.post('/editorParams', (req, res) => {
    const sql = "update params set param=? where category=?";
    let arr = [req.query.params,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});


router.post('/deleteParams', (req, res) => {
    const sql = "update params set param=? where category=?";
    let arr = [req.query.params,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});


router.get('/getProp', (req, res) => {
    const sql = "select * from params where category=?";
    let arr = [req.query.property]
    sqlFn(sql, arr, (result) => {
        res.send({
            res_code: 1,
            data:result
        });
        console.log('result:',result)
    })
});

router.post('/setProp', (req, res) => {
    console.log('req:',req.query)
    const sql = "insert into params(category,property) values(?,?)";
    let arr = [req.query.category,req.query.property]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});

router.post('/addProp', (req, res) => {
    const sql = "update params set property=? where category=?";
    let arr = [req.query.property,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});


router.post('/editorProp', (req, res) => {
    const sql = "update params set property=? where category=?";
    let arr = [req.query.property,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});


router.post('/deleteProp', (req, res) => {
    const sql = "update params set property=? where category=?";
    let arr = [req.query.property,req.query.category]
    sqlFn(sql, arr, (result) => {
        console.log('result:', result)
        res.send({
            res_code: 1,
        });
    })
});

module.exports = router